#include <stdio.h>
#include <math.h>
#include <string.h>
#include <sys/time.h>
#include <stdlib.h>
#include <unistd.h>

int main(int argc, char const *argv[])
{
/*
    char *p="hello word!!";
    char str[]={"hello word!!"};

    str[0]='H';
    printf("p=%s\n",p);
    printf("str=%s\n",str);

    char * week[]={"Mon","Tue","Wed","Thu","Fri","Sat","Sun"};

    printf("sizeof(week)=%d\n",sizeof(week));
    printf("sizeof(week[0])=%d\n",sizeof(week[0]));

    for (int i = 0; i < sizeof(week)/sizeof(week[0]); i++)
    {
        printf("week[%d]=%s\n",i,week[i]);
    }
  

    //随机点名
    char *class[]={"林  涛","张美玲","姬  璐","胡衍宇","张玉环","黄家洁",
                   "罗  瑞","兰天祥","李  丹","李成龙","何  昕","陈明东",
                   "张  蕊","王金程","赵  拥","王  策","崔志荣","赵世龙",
                   "李锦程","张泽宇","董泽奇","孙星座","李海波","孙田宇",
                   "梁慧靓","单喜丰"};
    struct timeval tv;      //定义时间结构体
    struct timezone tz;     //定义时区结构体
    gettimeofday(&tv,&tz);  //获取系统时间
    printf("tv.tv_usec=%d\n",tv.tv_usec);   //获取系统时间的微妙数
    srand(tv.tv_usec);      //安装随机因子
    int num = 0;        //随机数
    //printf("num=%d\n",num);
    for (int i = 0; i < 50; i++)
    {
        num = rand()%(sizeof(class)/sizeof(class[0]));  //num = rand()%26
        printf("姓名为: %s\r",class[num]);
        usleep(5000);
    }
    printf("\n");


    int a = 10;
    const int * pa = &a;    //限制通过指针改变其目标的数值
    //pa = 20;      
    pa++;       //可以修改指针变量的值 

    int * const pb = &a;    //指针变量的值不能修改
    * pb = 20;      //可以修改指针变量的值 
    //pb++;

    const int * const pc = &a;  // 指针变量的值不能修改, 不可以通过指针改变其目标的数值
    //pc = 20;
    //pc++;
*/

    char *p = NULL;     //定义一个指针变量量，赋初始值
    void *ptr = NULL;
    //void *malloc（size_t size）；
    //函数功能：申请指定大小的内存字节数
    //size：要申请内存的字节数
    //返回值：void * 类型的地址

    ptr = malloc(128);      //申请128字节的内存
    p = (char *)ptr;        //强转程需要的类型
    strcpy(p,"helloword");  //向p保存地址中写入 helloWord 字符串，以'\0'结束
    printf("p=%s\n",p);

    int *p1 = NULL;
    p1 =(int *)ptr;     //强转成需要 int * 类型
    *p1 = 100;          //把内存的前4个字节内存，对内存进行操作，写入100
    printf("*p1=%d\n",*p1);

    float *p2 = NULL;
    p2 = (float *)ptr;  //强转成需要 float * 类型
    *p2 = 100.234;      //把内存的前4个字节内存，对内存进行操作，写入100.234
    printf("*p2=%.3f\n",*p2);
  
    return 0;
}
